<include file="public:header" />
<include file="public:left" />
<style>
    #select-area select{height:30px;}
</style>
<form  method="post" enctype="multipart/form-data" id="brandForm" name="brandForm">
<input type="hidden" name="activity_id" value="{$activity_id?$activity_id:''}">
    <section>
        <h2><strong>添加活动</strong></h2>
        <ul class="ulColumn2">
            <li>
                <span class="item_name" style="width:120px;">活动标题：</span>
                <input type="text" class="textbox textbox_295" name="title" id="title" placeholder="活动标题" value="{$activity['title']?$activity['title']:''}"/>
            </li>
            <li>
                <span class="item_name" style="width:120px;">开启时间：</span>
                <input type="text" class="textbox textbox_295" name="start_time" id="start_date" placeholder="开始时间" value="{$activity['start_time']?$activity['start_time']:''}"/>
            </li>
            <li>
                <span class="item_name" style="width:120px;">关闭时间：</span>
                <input type="text" class="textbox textbox_295" name="end_time" id="end_date" placeholder="到期时间" value="{$activity['end_time']?$activity['end_time']:''}"/>
            </li>
            <li>
                <span class="item_name" style="width:120px;">抽奖间隔天数：</span>
                <input type="number" class="textbox textbox_295" name="lottery_time" id="title" placeholder="整数" value="{$activity['lottery_time']}"/>
            </li>
            <li>
                <span class="item_name" style="width:120px;">可抽奖次数：</span>
                <input type="number" class="textbox textbox_295" name="number_draws" id="title" placeholder="整数" value="{$activity['number_draws']?$activity['number_draws']:''}"/>
            </li>
            <li>
                <span class="item_name" style="width:120px;">活动描述：</span>
                <script id="editor" name="content" type="text/plain" style="width:700px;height:300px;margin-left:125px; margin-top:-12px;">{$activity['description']?$activity['description']:''}</script>
            </li>
            <li>
                <span class="item_name" style="width:120px;"></span>
                <input type="button" class="link_btn" value="提交"/>
            </li>
        </ul>
    </section>
</form>
<!--tabStyle-->
<style type="text/css" src="__STATIC__/admin/js/laydate/need/laydate.css"></style>
<script src="__STATIC__/admin/js/laydate/laydate.js"></script>

<script type="text/javascript">
    $(document).ready(function(){
        laydate({
            elem: '#start_date', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
            format: 'YYYY-MM-DD hh:mm:ss',
            istime: true,
            event: 'focus' //响应事件。如果没有传入event，则按照默认的click
        });

        laydate({
            elem: '#end_date', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
            format: 'YYYY-MM-DD hh:mm:ss',
            istime: true,
            event: 'focus' //响应事件。如果没有传入event，则按照默认的click
        });
        activity_id={$activity_id};
        // alert(activity_id);
        $(".link_btn").click(function(){
            if($("#title").val()==""){
                layer.alert("活动名称为空!");
                return false;
            }

            if($("#lottery_time").val()<0){
                layer.alert("天数不能为负");
                return false;
            }

            if($("#number_draws").val()<0){
                layer.alert("抽奖次数不能为负");
                return false;
            }

            if($("#start_time").val() == ''){
                layer.alert("请选择开启活动日期");
                return false;
            }

            if($("#end_time").val() == ''){
                layer.alert("请选择开启活动日期");
                return false;
            }

            var formData = new FormData();
            var title = $('input[name="title"]').val();
            var start_time = $('input[name="start_time"]').val();
            var end_time = $('input[name="end_time"]').val();

            var lottery_time = $('input[name="lottery_time"]').val();
            var number_draws = $('input[name="number_draws"]').val();
            var activity_id = $('input[name="activity_id"]').val();
            var content = ue.getContent();

            formData.append('title',title);
            formData.append('start_time',start_time);
            formData.append('end_time',end_time);
            formData.append('lottery_time',lottery_time);
            formData.append('number_draws',number_draws);
            formData.append('content',content);
            formData.append('activity_id',activity_id);
            
           
            $.ajax({

                url:"{:url('Activity/doedit')}?activity_id="+activity_id,
                type:'POST',
                data:formData,
                async:false,
                processData:false,
                contentType:false,
                success:function(result){
                   // console.log(result);
                    //alert();
                    //return;
                    if(result.code == '0'){
                        layer.alert(result.msg);
                    }else{
                        layer.alert(result.msg, {
                                    btn: ['确定']
                                },
                        function (index, item) {
                            location.href = result.url;
                        });
                    }
                }

            });

        });
    });

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');

    function isFocus(e){
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e){
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }
</script>
</div>
</section>
</body>
</html>
